var newsTable;
function getNewsList(name) {
    if (typeof newsTable !== 'undefined') {
        newsTable.fnPageChange('first');
        return;
    }
    var i = 1;
    newsTable = $("#newsList").DataTable({
        "sAjaxSource": _path + "/lhkgajnews/queryByPage",
        "fnServerParams": function (aoData) {
            aoData.push(
                { "name": "columnId", "value": $("#columnId").val() || $("#pid").val() },
                { "name": "status", "value": $("#status").val() },
                { "name": "fromDate", "value": $("#fromDate").val() },
                { "name": "toDate", "value": $("#toDate").val() },
                { "name": "keyType", "value": $("#keyType").val() },
                { "name": "value1", "value": $("#value1").val() }
            );
        },
        "sServerMethod": "POST",
        "sAjaxDataProp": "dataList",
        "fnCreatedRow": function () {
            i++;
        },
        "fnPreDrawCallback": function () {
            i = 1;
        },
        "aoColumns": [
            { "sTitle": "序号", "sWidth": "2%",
                "mData": function () {
                    return i;
                }
            },
        /*    { "sTitle": "标题", "sWidth": "10%", "mData":
            	function(data){
        		var temps = '<a href="' + _path + '/lhkgajnews/edit/' + data.id + '"  target="_blank">'+data.title+'</a>';
        		return temps;
        	}	
            }, */
            { "sTitle": "派工单名称", "mData": "value1", "sWidth": "40%" },
            { "sTitle": "作业命令号", "mData": "value4", "sWidth": "10%" },
            { "sTitle": "带班人", "mData": "value2", "sWidth": "10%" },
            { "sTitle": "工作地点", "mData": "value6", "sWidth": "10%" },
            { "sTitle": "作业负责人", "mData": "value23", "sWidth": "10%" },
//            { "sTitle": "栏目", "mData": "cv.value0", "sWidth": "10%" },
            
//            { "sTitle": "状态", "mData": "status", "sWidth": "10%",
//                "mRender": function (data) {
//                    var status = '';
//                    switch (data) {
//                        case '0':
//                            status = '投稿未审核';
//                            break;
//                        case '1':
//                            status = '有效';
//                            break;
//                        case '2':
//                            status = '投稿审核不通过';
//                            break;
//                        case '3':
//                            status = '置顶';
//                            break;
//                        case '4':
//                            status = '已复签';
//                            break;
//                        case '5':
//                            status = '主动公开';
//                            break;
//                        case '6':
//                            status = '依申请公开';
//                            break;
//                        case '7':
//                            status = '不予公开';
//                            break;
//                        case '8':
//                            status = '无效';
//                            break;
//                        default :
//                            status = '有效';
//                            break;
//                    }
//                    return status;
//                }
//            },
            { "sTitle": "发布时间", "mData": "falseCreateTime", "sWidth": "10%" },
            { "sTitle": "操作", "sWidth": "15%",
                "mData": function (data) {
                    var status = '<a    class="btn default btn-xs purple"><i class="fa fa-edit" onclick="check(this)"  id="'+data.id+'"  uname="'+data.username+'" title="编辑"></i></a>';
                    status += '&nbsp;<a    class="btn default btn-xs red"><i class="fa fa-trash-o" onclick="oke(this)"  id="'+data.id+'"  uname="'+data.username+'" title="删除"></i></a>';
                    /*if(data.columnId==9670 || data.columnId==9802 || data.columnId==9672 || data.columnId==9665 || data.columnId==9920 || data.columnId==9921 || data.columnId==9922)
                    status += '&nbsp;<a href="' + _path + '/news/stickie/' + data.id + '"  class="btn default btn-xs blue"><i class="fa fa-edit" title="置顶"></i></a>';
                    if(data.columnId!=9670 && data.columnId!=9920 && data.columnId!=9921 && data.columnId!=9922)
                    status += '&nbsp;<a href="' + _path + '/notice/counterSign/' + data.id +'?name='+name+ '" class="btn default btn-xs green"><i class="fa fa-edit" title="复签"></i></a>';*/
                    return status;
                }
            }
        ]
    });
}
function oke(em){
	var name =document.getElementById("username").value;
	var uname=$(em).attr('uname');
	var id=$(em).attr('id');
	
	if (name==uname || name=="admin") {
		layer.alert(id);
		layer.confirm('您确定要删除吗？', function(){
			location.href = _path + "/lhkgajnews/del/" + id;
		}, function(){
		
		});
	} else {
		layer.alert('对不起你没有权限');
	}

}

function check(em){
	var name =document.getElementById("username").value;
	var uname=$(em).attr('uname');
	var id=$(em).attr('id');
	
	if (name==uname || name=='admin') {
			//window.open( _path + "/lhkgajnews/edit/" + id);
		location.href = _path + "/lhkgajnews/edit/" + id;
	} else {
		layer.alert('对不起你没有权限');
	}

}

